
package com.foreveross.mofang.serviceconsole.web.controller.interfaces;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import org.dayatang.querychannel.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.foreveross.mofang.serviceconsole.application.core.ChannelApplication;
import com.foreveross.mofang.serviceconsole.application.core.GroupApplication;
import com.foreveross.mofang.serviceconsole.application.dto.ChannelDTO;
import com.foreveross.mofang.serviceconsole.core.ChannelGroup;
import com.foreveross.mofang.serviceconsole.web.controller.common.BaseController;
import com.foreveross.mofang.serviceconsole.web.controller.common.LogAn;

/**
 * 渠道管理对外开放调用入口
 * 
 * @author fb
 *
 */
@Controller
@RequestMapping("/interface/Channel")
public class ChannelInterface extends BaseController{
		
	@Inject
	private ChannelApplication channelApplication;
	
	@Inject
	private GroupApplication groupApplication;
	
	@LogAn(name = "渠道获取" , params = {"sn"})
	@ResponseBody
	@RequestMapping("/getChannel")
	public Map<String, Object> getChannel(ChannelDTO channelDTO) {
		Map<String, Object> result = new HashMap<String, Object>();
		Page<ChannelDTO> all = channelApplication.pageQueryChannel(channelDTO, 1, Integer.MAX_VALUE);
		result.put("data", all.getData());
		return result;
	}
	
	@LogAn(name = "组获取组根结点" ,params = {"nodeSn"})
	@ResponseBody
	@RequestMapping("/getGroupRoot")
	public Map<String, Object> channelGetRoots(@RequestParam String nodeSn) {
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("data", groupApplication.getRoots(ChannelGroup.class));
		return result;
	}
	
	@LogAn(name = "所有组获取(无树型结构)" ,params = {"nodeSn"})
	@ResponseBody
	@RequestMapping("/getGroups")
	public Map<String, Object> allGroup(@RequestParam String nodeSn) {
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("data", groupApplication.findAllGroup());
		return result;
	}
}
